package com.ct.musicserver.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ct.musicserver.dao.dataobject.MusicDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface MusicMapper extends BaseMapper<MusicDO> {

    @Select("select * from music where singer = #{singer} and title = #{title}")
    MusicDO selectBySingerAndFile(@Param("singer") String singer,
                              @Param("title") String title);

    @Update("update music set status = 0 where id = #{id}")
    void deleteMusicById(@Param("id") Long id);

    @Update("update music set status = 1 where id = #{id}")
    void uploadMusicById(@Param("id") Long id);

    @Select("select * from music where title like concat('%',#{musicName},'%') and status = 1")
    List<MusicDO> selectByMusicName(@Param("musicName") String musicName);

    @Select("select * from music where status = 1")
    List<MusicDO> selectMusic();

    @Select("select * from music where status = 1 and userid = #{userid}")
    List<MusicDO> selectMusicByUserId(@Param("userid") Long userid);

    @Select("select * from music where status = 1 and id = #{id}")
    MusicDO selectByMusicId(@Param("id") Long id);
}
